# accounting_cn/accounting_cn/api.py
import frappe
from frappe import _

@frappe.whitelist()
def get_voucher_series():
    """从GL Entry中提取所有不同的voucher_series"""
    gl_entries = frappe.get_all("GL Entry", fields=["voucher_no"])
    
    # 存储所有唯一的voucher_series
    series_set = set()
    
    for entry in gl_entries:
        if entry.voucher_no:
            parts = entry.voucher_no.split('-')
            # 保留所有非数字部分
            series_parts = []
            for part in parts:
                if not part.isdigit():
                    series_parts.append(part)
            
            if series_parts:
                # 重新组合为前缀，例如："ACC-PAY"
                series = '-'.join(series_parts)
                series_set.add(series)
    
    # 转换为列表并排序
    return sorted(list(series_set))